﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OAProject.Domain.Entities;
using OAProject.Infrastructure.Data;
using Dapper;
using Microsoft.Extensions.Configuration;
using OAProject.Domain.Interfaces;

/// <summary>
/// 用户实现类
/// </summary>
namespace OAProject.Infrastructure.Data
{
    public class UsersRepository : DapperRepository<Users>, IUsersRepository
    {
        //依赖注入
        public IConfiguration _configuration;

        public UsersRepository(IConfiguration configuration)
        {
            this._configuration = configuration;
            //连接字符串
            this.ConnStr = _configuration.GetConnectionString("ConnStr");
            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
            Conn = new MySql.Data.MySqlClient.MySqlConnection(this.ConnStr);
        }

        /// <summary>
        /// 忘记密码
        /// </summary>
        /// <param name="loginname"></param>
        /// <returns></returns>
        public Users ForgetPwd(string loginname)
        {
            var ulist = Conn.GetList<Users>().ToList();
            var result = ulist.FirstOrDefault(m => m.LoginName.Equals(loginname));
            return result;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public Users Login(Users obj)
        {
            var uList = Conn.GetList<Users>().ToList();
            var result = uList.FirstOrDefault(m => m.LoginName.Equals(obj.LoginName) && m.Pwd.Equals(obj.Pwd));
            return result;
        }

    }
}
